import Vue from 'vue'
import Router from 'vue-router'
import home from '@/components/home'
import index from '@/components/index'
import good from '@/components/good'
import exchange from '@/components/exchange'
import seckill from '@/components/seckill'
import mustbe from '@/components/mustbe'
import auction from '@/components/auction'
import detail from '@/components/detail'
import detailAuction from '@/components/detailAuction'
import agent from '@/components/agent'
import agentCenter from '@/components/agentCenter'
import store from '@/components/store'
import release from '@/components/release'
import releaseAuction from '@/components/releaseAuction'
import manage from '@/components/manage'
import manageAuction from '@/components/manageAuction'
import taskDetail from '@/components/taskDetail'
import userList from '@/components/userList'
import userDetail from '@/components/userDetail'
import taskDetailAuction from '@/components/taskDetailAuction'
import userListAuction from '@/components/userListAuction'
import userDetailAuction from '@/components/userDetailAuction'
import recharge from '@/components/recharge'
import vip from '@/components/vip'
import certification from '@/components/certification'
import information from '@/components/information'
import validation from '@/components/validation'
import revisePassword from '@/components/revise-password'
import bankCard from '@/components/bankCard'
import withdrawal from '@/components/withdrawal'
import news from '@/components/news'
import feedback from '@/components/feedback'
import spread from '@/components/spread'
import spreadList from '@/components/spreadList'
import IDoperation from '@/components/IDoperation'
import login from '@/components/login'
import register from '@/components/register'
import forget from '@/components/forget'
import agreement from '@/components/agreement'
import joinAgent from '@/components/joinAgent'
import share from '@/components/share'
import about from '@/components/about'
import help from '@/components/help'
import channel from '@/components/channel'
Vue.use(Router)
const router = new Router({
//	mode: 'history',
  routes: [
    { path: '/', redirect: '/home' }, // 默认跳转页面
    {
      path: '/home',
      name: 'home',
      component: home,
      redirect: '/home/index',
      children: [
      	{
		      path: '/home/index',
		      name: 'index',
		      component: index,
		      meta:{title:'首页'},
		    },
      	{
		      path: '/home/good',
		      name: 'good',
		      component: good,
		      meta:{title:'精选好货'}
		    },
		    {
		      path: '/home/exchange',
		      name: 'exchange',
		      component: exchange,
		      meta:{title:'金币兑换'}
		    },
		    {
		      path: '/home/seckill',
		      name: 'seckill',
		      component: seckill,
		      meta:{title:'限量秒杀'}
		    },
		    {
		      path: '/home/mustbe',
		      name: 'mustbe',
		      component: mustbe,
		      meta:{title:'新人必中'}
		    },
		    {
		      path: '/home/auction',
		      name: 'auction',
		      component: auction,
		      meta:{title:'赶紧拍'}
		    },
		    {
		      path: '/home/detail',
		      name: 'detail',
		      component: detail,
		      meta:{title:'试用详情'}
		    },
		    {
		      path: '/home/detailAuction',
		      name: 'detailAuction',
		      component: detailAuction,
		      meta:{title:'拍卖详情'}
		    },
      ]
    },
    {
      path: '/agent',
      name: 'agent',
      component: agent,
      redirect: '/agent/agentCenter',
      meta:{
      	requireAuth: true,
      },
      children: [
      	{
		    path: '/agent/agentCenter',
		    name: 'agentCenter',
		    component: agentCenter,
		    meta:{title:'个人中心'}
		},
      	{
		    path: '/agent/store',
		    name: 'store',
		    component: store,
		    meta:{title:'店铺管理'}
		},
      	{
		    path: '/agent/manage',
		    name: 'manage',
		    component: manage,
		    meta:{title:'试用管理'}
		},
      	{
		    path: '/agent/manageAuction',
		    name: 'manageAuction',
		    component: manageAuction,
		    meta:{title:'拍卖管理'}
		},
      	{
		    path: '/agent/detail',
		    name: 'taskDetail',
		    component: taskDetail,
		    meta:{title:'试用信息'},
		    redirect: '/agent/detail/userList',
		    children: [
		    	{
		    		path: '/agent/detail/userList',
				    name: 'userList',
				    component: userList,
				    meta:{title:'试用信息'}
		    	},
		    	{
		    		path: '/agent/detail/userDetail',
				    name: 'userDetail',
				    component: userDetail,
				    meta:{title:'试用信息'}
		    	},
		    ]
		},
      	{
		    path: '/agent/auction',
		    name: 'taskDetailAuction',
		    component: taskDetailAuction,
		    meta:{title:'拍卖信息'},
		    redirect: '/agent/detailAuction/userListAuction',
		    children: [
		    	{
		    		path: '/agent/detailAuction/userListAuction',
				    name: 'userListAuction',
				    component: userListAuction,
				    meta:{title:'拍卖信息'}
		    	},
		    	{
		    		path: '/agent/detailAuction/userDetailAuction',
				    name: 'userDetailAuction',
				    component: userDetailAuction,
				    meta:{title:'拍卖信息'}
		    	},
		    ]
		},
      	{
		    path: '/agent/release',
		     name: 'release',
		    component: release,
		    meta:{title:'发布试用'}
		},
      	{
		    path: '/agent/releaseAuction',
		     name: 'releaseAuction',
		    component: releaseAuction,
		    meta:{title:'发布拍卖'}
		},
      	{
		    path: '/agent/recharge',
		    name: 'recharge',
		    component: recharge,
		    meta:{title:'账户充值'}
		},
      	{
		    path: '/agent/vip',
		    name: 'vip',
		    component: vip,
		    meta:{title:'升级VIP'}
		},
      	{
		    path: '/agent/certification',
		    name: 'certification',
		    component: certification,
		    meta:{title:'安全认证'}
		},
      	{
		    path: '/agent/validation',
		    name: 'validation',
		    component: validation,
		    meta:{title:'安全认证'}
		},
      	{
		    path: '/agent/revisePassword',
		    name: 'revisePassword',
		    component: revisePassword,
		    meta:{title:'修改密码'}
		},
      	{
		    path: '/agent/information',
		    name: 'information',
		    component: information,
		    meta:{title:'个人资料'}
		},
      	{
		    path: '/agent/bankCard',
		    name: 'bankCard',
		    component: bankCard,
		    meta:{title:'我的提现账户'}
		},
      	{
		    path: '/agent/withdrawal',
		    name: 'withdrawal',
		    component: withdrawal,
		    meta:{title:'提现/账户明细'}
		},
      	{
		    path: '/agent/feedback',
		    name: 'feedback',
		    component: feedback,
		    meta:{title:'意见反馈'}
		},
      	{
		    path: '/agent/news',
		    name: 'news',
		    component: news,
		    meta:{title:'消息'}
		},
      	{
		    path: '/agent/spread',
		    name: 'spread',
		    component: spread,
		    meta:{title:'邀请商家'}
		},
      	{
		    path: '/agent/spreadList',
		    name: 'spreadList',
		    component: spreadList,
		    meta:{title:'已邀请商家'}
		},
      ]
    },
    {
      path: '/IDoperation',
      name: 'IDoperation',
      component: IDoperation,
      redirect: '/IDoperation/login',
      children:[
      	{
	      path: '/IDoperation/login',
	      name: 'login',
	      component: login,
	      meta:{title:'登录'}
	    },
	    {
	      path: '/IDoperation/register',
	      name: 'register',
	      component: register,
	      meta:{title:'注册'}
	    },
	    {
	      path: '/IDoperation/forget',
	      name: 'forget',
	      component: forget,
	      meta:{title:'忘记密码'}
	    },
      ]
    },
    {
      path: '/agreement',
      name: 'agreement',
      component: agreement,
      meta:{title:'用户协议'}
    },
    {
      path: '/joinAgent',
      name: 'joinAgent',
      component: joinAgent,
      meta:{title:'商家报名'}
    },
    {
      path: '/share',
      name: 'share',
      component: share,
      meta:{title:'分享赚钱'}
    },
    {
      path: '/about',
      name: 'about',
      component: about,
      meta:{title:'关于我们'}
    },
    {
      path: '/help',
      name: 'help',
      component: help,
      meta:{title:'帮助中心'}
    },
    {
      path: '/channel',
      name: 'channel',
      component: channel,
      meta:{title:'赶紧试'}
    },
  ],
	scrollBehavior(to, from, savedPosition){
	  // return 期望滚动到哪个的位置
	  return { x: 0, y: 0 }
	}
})
router.beforeEach((to, from, next) => {
    if (to.matched.some(r => r.meta.requireAuth)) {
    	var token = localStorage.getItem('token');
        if (token) {
            next();
        }
        else {
            next({
                path: '/IDoperation/login',
                query: {redirect: to.path}
            })
        }
    }
    else {
        next();
    }
})
export default router;
